<template>
  <div class="container">
    <el-dialog
      title="添加发票"
      :visible.sync="dialog.centerDialogVisible"
      width="1500px"
      center
      :lock-scroll="true"
      @close="hideDialog"
    >
      <div class="main">
        <el-form label-width="170px" label-position="left">
          <el-form-item label="发票号码：">
            <el-input
              v-model="formData.invoice_num"
              placeholder="请输入发票号码"
            />
          </el-form-item>
          <el-form-item label="发票代码：">
            <el-input
              v-model="formData.invoice_code"
              placeholder="请输入发票代码"
            />
          </el-form-item>
          <el-form-item label="不含税金额：">
            <el-input
              v-model="formData.not_tax_amount"
              placeholder="请输入不含税金额"
            />
          </el-form-item>
          <el-form-item label="开票日期：">
            <el-input
              v-model="formData.billing_date_rq"
              placeholder="请输入开票日期"
            />
          </el-form-item>
          <el-form-item label="校验码：">
            <el-input
              v-model="formData.check_code"
              placeholder="请输入校验码"
            />
          </el-form-item>
          <el-form-item label="销售方纳税人识别号：">
            <el-input
              v-model="formData.sale_identifier"
              placeholder="请输入销售方纳税人识别号"
            />
          </el-form-item>
          <el-form-item label="销售方名称：">
            <el-input
              v-model="formData.sale_name"
              placeholder="请输入销售方名称"
            />
          </el-form-item>
          <el-form-item label="销售方开户行及帐号：">
            <el-input
              v-model="formData.sale_bank_and_account"
              placeholder="请输入销售方开户行及帐号"
            />
          </el-form-item>
          <el-form-item label="销货单位开户银行：">
            <el-input
              v-model="formData.sale_bank"
              placeholder="请输入销货单位开户银行"
            />
          </el-form-item>
          <el-form-item label="销售方地址、电话：">
            <el-input
              v-model="formData.sale_address_and_tel"
              placeholder="请输入销售方地址、电话"
            />
          </el-form-item>
          <el-form-item label="销货单位地址：">
            <el-input
              v-model="formData.sale_address"
              placeholder="请输入销货单位地址"
            />
          </el-form-item>
          <el-form-item label="销货单位电话：">
            <el-input
              v-model="formData.sale_tel"
              placeholder="请输入销货单位电话"
            />
          </el-form-item>
        </el-form>
        <el-form label-width="170px" label-position="left">
          <el-form-item label="购买方纳税人识别号：">
            <el-input
              v-model="formData.buy_identifier"
              placeholder="请输入购买方纳税人识别号"
            />
          </el-form-item>
          <el-form-item label="购买方名称：">
            <el-input
              v-model="formData.buy_name"
              placeholder="请输入购买方名称"
            />
          </el-form-item>
          <el-form-item label="购买方开户行及帐号：">
            <el-input
              v-model="formData.buy_bank_and_account"
              placeholder="请输入购买方开户行及帐号"
            />
          </el-form-item>
          <el-form-item label="购买方地址、电话：">
            <el-input
              v-model="formData.buy_address_and_tel"
              placeholder="请输入购买方地址、电话"
            />
          </el-form-item>
          <el-form-item label="价税合计大写：">
            <el-input
              v-model="formData.price_in_words"
              placeholder="请输入价税合计大写"
            />
          </el-form-item>
          <el-form-item label="价税合计小写：">
            <el-input
              v-model="formData.price_in_figures"
              placeholder="请输入价税合计小写"
            />
          </el-form-item>
          <el-form-item label="税额合计：">
            <el-input
              v-model="formData.total_tax"
              placeholder="请输入税额合计"
            />
          </el-form-item>
          <el-form-item label="货物或服务名称：">
            <el-input
              v-model="formData.goods_services_name"
              placeholder="请输入货物或服务名称"
            />
          </el-form-item>
          <el-form-item label="金额明细：">
            <el-input
              v-model="formData.amount_detailed"
              placeholder="请输入金额明细"
            />
          </el-form-item>
          <el-form-item label="税率明细：">
            <el-input
              v-model="formData.tax_rate_detailed"
              placeholder="请输入税率明细"
            />
          </el-form-item>
          <el-form-item label="税额明细：">
            <el-input
              v-model="formData.tax_amount_detailed"
              placeholder="请输入税额明细"
            />
          </el-form-item>
          <el-form-item label="票据：">
            <el-select v-model="formData.ticket_type" placeholder="请选择票据">
              <el-option
                v-for="item in ticket_typeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form label-width="170px" label-position="left">
          <el-form-item label="代开(非代开条目为空)：">
            <el-input
              v-model="formData.daikai"
              placeholder="请输入代开(非代开条目为空)"
            />
          </el-form-item>
          <el-form-item label="规格型号明细：">
            <el-input
              v-model="formData.spec_and_model"
              placeholder="请输入规格型号明细"
            />
          </el-form-item>
          <el-form-item label="单位明细：">
            <el-input v-model="formData.unit" placeholder="请输入单位明细" />
          </el-form-item>
          <el-form-item label="数量明细：">
            <el-input
              v-model="formData.quantity"
              placeholder="请输入数量明细"
            />
          </el-form-item>
          <el-form-item label="单价明细：">
            <el-input
              v-model="formData.unit_price"
              placeholder="请输入单价明细"
            />
          </el-form-item>
          <el-form-item label="票联：">
            <el-select
              v-model="formData.deduction_invoice"
              placeholder="请选择票联"
            >
              <el-option
                v-for="item in deduction_invoiceList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发票类型：">
            <el-input
              v-model="formData.invoice_type"
              placeholder="请输入发票类型"
            />
          </el-form-item>
          <el-form-item label="备注：">
            <el-input v-model="formData.remark" placeholder="请输入备注" />
          </el-form-item>
          <el-form-item label="密码区：">
            <el-input
              v-model="formData.password_area"
              placeholder="请输入密码区"
            />
          </el-form-item>
          <el-form-item label="开票人：">
            <el-input v-model="formData.drawer" placeholder="请输入开票人" />
          </el-form-item>
          <el-form-item label="盖章存在性判断：">
            <el-input
              v-model="formData.seal_mark"
              placeholder="请输入盖章存在性判断"
            />
          </el-form-item>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { addinvoice } from "@/api/invoice/invoiceList";
export default {
  props: {
    dialog: Object,
  },
  data() {
    return {
      formData: {
        invoice_num: "",
        invoice_code: "",
        not_tax_amount: "",
        billing_date_rq: "",
        check_code: "",
        sale_identifier: "",
        sale_name: "",
        sale_bank_and_account: "",
        sale_bank: "",
        sale_address_and_tel: "",
        sale_address: "",
        sale_tel: "",
        buy_identifier: "",
        buy_name: "",
        buy_bank_and_account: "",
        buy_address_and_tel: "",
        price_in_words: "",
        price_in_figures: "",
        total_tax: "",
        goods_services_name: "",
        amount_detailed: "",
        tax_rate_detailed: "",
        tax_amount_detailed: "",
        ticket_type: "",
        daikai: "",
        spec_and_model: "",
        unit: "",
        quantity: "",
        unit_price: "",
        deduction_invoice: "",
        invoice_type: "",
        remark: "",
        password_area: "",
        drawer: "",
        seal_mark: "",
      },
      deduction_invoiceList: [
        {
          value: "1",
          label: "抵扣联",
        },
        {
          value: "2",
          label: "发票联",
        },
      ],
      ticket_typeList: [
        {
          value: "1",
          label: "专票",
        },
        {
          value: "2",
          label: "普票",
        },
      ],
    };
  },

  methods: {
    hideDialog() {
      this.dialog.centerDialogVisible = false;
    },

    //提交
    confirm() {
      let data = {
        invoice_num: this.formData.invoice_num,
        invoice_code: this.formData.invoice_code,
        not_tax_amount: this.formData.not_tax_amount,
        billing_date_rq: this.formData.billing_date_rq,
        check_code: this.formData.check_code,
        sale_identifier: this.formData.sale_identifier,
        sale_name: this.formData.sale_name,
        sale_bank_and_account: this.formData.sale_bank_and_account,
        sale_bank: this.formData.sale_bank,
        sale_address_and_tel: this.formData.sale_address_and_tel,
        sale_address: this.formData.sale_address,
        sale_tel: this.formData.sale_tel,
        buy_identifier: this.formData.buy_identifier,
        buy_name: this.formData.buy_name,
        buy_bank_and_account: this.formData.buy_bank_and_account,
        buy_address_and_tel: this.formData.buy_address_and_tel,
        price_in_words: this.formData.price_in_words,
        price_in_figures: this.formData.price_in_figures,
        total_tax: this.formData.total_tax,
        goods_services_name: this.formData.goods_services_name,
        amount_detailed: this.formData.amount_detailed,
        tax_rate_detailed: this.formData.tax_rate_detailed,
        tax_amount_detailed: this.formData.tax_amount_detailed,
        ticket_type: this.formData.ticket_type,
        daikai: this.formData.daikai,
        spec_and_model: this.formData.spec_and_model,
        unit: this.formData.unit,
        quantity: this.formData.quantity,
        unit_price: this.formData.unit_price,
        deduction_invoice: this.formData.deduction_invoice,
        invoice_type: this.formData.invoice_type,
        remark: this.formData.remark,
        password_area: this.formData.password_area,
        drawer: this.formData.drawer,
        seal_mark: this.formData.seal_mark,
      };
      addinvoice(data)
        .then((res) => {
          if (res.code == 0) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.hideDialog();
            this.$emit("upData");
          } else {
            this.$message({
              message: res.msg,
              type: "error",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //取消
    cancel() {
      this.hideDialog();
    },
  },
};
</script>
<style scoped>
.main {
  display: flex;
  justify-content: space-between;
}
.main .el-input {
  width: 250px;
}
</style>
